package com.sti.framework.models.Aps.controller;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.sti.framework.core.controller.BaseController;
import com.sti.framework.core.web.Page;
import com.sti.framework.core.web.ResponseBodyEntity;
import com.sti.framework.models.Aps.data.ApsMonthPlanMoGroup;
import com.sti.framework.models.Aps.data.ApsMonthPlanMoResult;
import com.sti.framework.models.Aps.data.ApsMonthPlanMoWhere;
import com.sti.framework.models.Aps.mapper.ApsMonthPlanMoResultMapper;
import com.sti.framework.models.Aps.service.ApsMonthPlanMoResultService;
import com.sti.framework.models.Basics.data.BasicsParameterSearchWhere;
import org.apache.commons.lang3.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/Api/ApsMonthPlanMoResult")
public class ApsMonthPlanMoTableController extends BaseController<ApsMonthPlanMoResultMapper, ApsMonthPlanMoResult, ApsMonthPlanMoWhere> {

    @Resource
    private ApsMonthPlanMoResultService apsMonthPlanMoResultService;

    /**
     * 列表
     *
     * @param page        分页内容
     * @param searchWhere 搜索内容
     * @return
     */
    @GetMapping("/ListPage")
    public ResponseBodyEntity listPage(Page page, BasicsParameterSearchWhere searchWhere) {
        LambdaQueryWrapper<ApsMonthPlanMoResult> queryWrapper = new LambdaQueryWrapper<>();
        //班组
        if (StringUtils.isNotEmpty(searchWhere.getClassTypeGroup())) {
            queryWrapper.eq(ApsMonthPlanMoResult::getClassType, searchWhere.getClassTypeGroup());
        }
        //开始时间
        if(StringUtils.isNotEmpty(searchWhere.getScheduleStartDate())){
            queryWrapper.ge(ApsMonthPlanMoResult::getScheduleDate, searchWhere.getScheduleStartDate());
        }
        //结束时间
        if(StringUtils.isNotEmpty(searchWhere.getScheduleEndDate())){
            queryWrapper.le(ApsMonthPlanMoResult::getScheduleDate, searchWhere.getScheduleEndDate());
        }
        queryWrapper.isNull(ApsMonthPlanMoResult::getExecuteException);
        queryWrapper.isNull(ApsMonthPlanMoResult::getBaseDataException);
        queryWrapper.eq(ApsMonthPlanMoResult::getDeleted,0);
        return ResponseBodyEntity.success(apsMonthPlanMoResultService.getByClassGroupList(page, queryWrapper));
    }

    /**
     * 列表
     *
     * @param page        分页内容
     * @param searchWhere 搜索内容
     * @return
     */
    @GetMapping("/InfoListPage")
    public ResponseBodyEntity infoListPage(Page page, BasicsParameterSearchWhere searchWhere) {
        LambdaQueryWrapper<ApsMonthPlanMoResult> queryWrapper = new LambdaQueryWrapper<>();
        //铸造时间
        if (StringUtils.isNotEmpty(searchWhere.getScheduleDate())) {
            queryWrapper.eq(ApsMonthPlanMoResult::getScheduleDate, searchWhere.getScheduleDate());
        }
        //班次类型
        if (StringUtils.isNotEmpty(searchWhere.getClassType())) {
            queryWrapper.eq(ApsMonthPlanMoResult::getClassType, searchWhere.getClassType());
        }
        return ResponseBodyEntity.success(apsMonthPlanMoResultService.getListPage(page, queryWrapper));
    }


    /**
     * 根据日期和班次获取数据
     */
    @GetMapping("/ResultInfo")
    public ResponseBodyEntity resultInfo(BasicsParameterSearchWhere searchWhere) {
        LambdaQueryWrapper<ApsMonthPlanMoResult> queryWrapper = new LambdaQueryWrapper<>();
        //铸造时间
        if (StringUtils.isNotEmpty(searchWhere.getScheduleDate())) {
            queryWrapper.eq(ApsMonthPlanMoResult::getScheduleDate, searchWhere.getScheduleDate());
        }
        //班次类型
        if (StringUtils.isNotEmpty(searchWhere.getClassType())) {
            queryWrapper.eq(ApsMonthPlanMoResult::getClassType, searchWhere.getClassType());
        }
        queryWrapper.isNull(ApsMonthPlanMoResult::getExecuteException);
        queryWrapper.isNull(ApsMonthPlanMoResult::getBaseDataException);
        queryWrapper.eq(ApsMonthPlanMoResult::getDeleted,0);
        return ResponseBodyEntity.success(apsMonthPlanMoResultService.getByClassGroupListOne(queryWrapper));
    }
}
